<template>
  <div>
    <el-button type="primary" size="small" @click="onClickRefresh()"
      >刷新</el-button
    >
    <el-table :data="data" style="width: 100%" v-loading="loading">
      <el-table-column prop="id" label="序号" width="60px" align="center">
      </el-table-column>
      <el-table-column prop="name" label="房间名" min-width="250px">
      </el-table-column>
      <el-table-column
        prop="ranked"
        label="Ranked"
        min-width="80px"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="mapName" label="地图名" min-width="150px">
      </el-table-column>
      <el-table-column prop="mapId" label="地图ID" min-width="150px">
      </el-table-column>
      <el-table-column
        prop="approved"
        label="是否是批准图"
        min-width="110px"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="maxPlayers"
        label="房间人数"
        min-width="110px"
        align="center"
      >
        <template #default="scope">
          {{ `${scope.row.players ? scope.row.players.length : 0}` }}
          /
          {{ scope.row.maxPlayers }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from "vue";
import request from "../../request";
const data = ref<any[]>([]);
const loading = ref<Boolean>(false);
const props = defineProps({
  serverLocation: String,
});
onMounted(() => {
  getData();
});
const onClickRefresh = () => {
  getData();
};
const getData = async () => {
  loading.value = true;
  let param = {
    serverLocation: props.serverLocation,
  };
  let result = await request
    .get("/pbMatches/getMatchesList", param)
    .catch((error) => {
      console.log(error);
    });
  const json = result.data;
  data.value = json;
  loading.value = false;
};
</script>